/******************************************************
* Team WB
* Brett Cate, William Kim
* 
* Memory Module ADT Header
*******************************************************/

#ifndef SC2_H 
#include "sc2.h"
#endif

#ifndef MEMORYMODULE_H
#define MEMORYMODULE_H

typedef  uchar* MemoryModulePtr;

/* 
Creates user memory space and fills with random numbers.
*/
MemoryModulePtr memory_new(); 

/*
Creates a new IO memory module of the given size and returns a pointer to the module.

parameter(the_size): Int value of the size of the memory module to be created.

return value: Pointer to the memory module created.
*/
MemoryModulePtr memory_newIOMemory(int the_size);

/* 
Returns a byte from address.

parameter (mm): pointer to the memory module.
parameter (address): address to fetch byte from.
parameter (error): pointer to the int value for the error code of this function.

return value: the byte from the memory module at the given address.
*/
uchar memory_fetchByteFrom(MemoryModulePtr mm, ushort address, int * error);

/* 
Stores byte at address.

parameter (mm): pointer to the memory module.
parameter (address): address to store byte to.

return value: error code.
*/
int memory_storeByteTo(MemoryModulePtr mm, ushort address, uchar byte); 
	
/* 
Returns the contents of two consecutive locations starting at address.

parameter (mm): pointer to the memory module.
parameter (address):
parameter (error): pointer to the int value for the error code of this function.

return value: the word starting at the given address (big-endian).
*/
ushort memory_fetchWordFrom(MemoryModulePtr mm, ushort address, int * error); 

/* 
Stores the contents at two consecutive locations starting at address. 

parameter (mm): pointer to the memory module.
parameter (address): starting address to store word to (big-endian).

return value: error code.
*/
int memory_storeWordTo(MemoryModulePtr mm, ushort address, ushort word);

/*
Returns the byte at the given address of the given IO memory module.

parameter(the_mm): The memory module.
parameter(the_address): The address.
parameter(the_error): Pointer to the error code value.

return value: The uchar value at the given address.
*/
uchar memory_IOFetchByteFrom(MemoryModulePtr the_mm, ushort the_address, int* the_error);

/*
Puts the given byte at the given address of the memory module.

parameter(the_mm): The memory module.
parameter(the_address): The address.
parameter(the_byte): The byte to put at the given address.

return value: The int value of the error code.
*/
int memory_IOStoreByteTo(MemoryModulePtr the_mm, ushort the_address, uchar the_byte);


#endif

/* End Program */
